home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / ParamRAM guard / myenv.h < prev    next >
Encoding:
Text File  |  1993-08-06  |  3.1 KB  |  98 lines  |  [TEXT/KAHL]

  1. //************************************************************************
  2. //
  3. //                            A standard environment
  4. //                                I am accustomed to
  5.  
  6. #pragma once
  7. #ifndef _myenv_h
  8.  
  9. #define _myenv_h
  10. #pragma interface
  11.  
  12.                 // Strings of symbols
  13.                 // They may be used as a delimiting lines
  14. extern const char _Minuses [];
  15. extern const char _Asteriscs [];
  16. extern const char _Equals [];
  17.  
  18.                 // Print an error message at stderr and    abort
  19. volatile void _error(
  20.     const char * message,            // Message to be printed
  21.     ...                             // Additional args like in printf()
  22.        );
  23.                 // Set a custom fuction that would perform abort
  24.                 // nil means set up the standard abort function
  25. void set_abort_function(const volatile void (*custom_abort)(void));
  26.  
  27.                 // Print a message at stderr
  28. void message(
  29.     const char * text,                // Message to be printed
  30.     ...                             // Additional args to printf
  31.        );
  32.  
  33. class ErrHandler
  34. {
  35.     Boolean raise_hell;                // Raise the hell in case of error?
  36.     Boolean was_error;                // Has an error sneaked in whilst we're lenient?
  37.     
  38. public:
  39.     ErrHandler(void);
  40.     ~ErrHandler(void) {}
  41.     void error(const char * message,...);
  42.     void lenient(void);                        // Be lenient
  43.     Boolean was_ok(void);                    // Have we failed?
  44. };
  45.  
  46. //------------------------------------------------------------------------
  47. //                        Verify the assertion
  48.  
  49.  
  50. #define assert(ex) \
  51.         (void)((ex) ? 1 : \
  52.               (_error("Failed assertion " #ex " at line %ld of `%s'.", \
  53.                __LINE__, __FILE__), 0))
  54. #define assertval(ex) assert(ex)
  55.  
  56. #define assure(expr,message)                \
  57.     if    (expr) ;                \
  58.     else _error("%s at line %ld of '%s'.",message,__LINE__, __FILE__);
  59.  
  60.                                         // Execute the function 'ex' and make sure
  61.                                         // it return noErr
  62. #define do_well(ex) \
  63.         { OSErr err = (ex); if( err != noErr ) \
  64.               _error("Failed call " #ex " with error %ld at line %ld of `%s'.", \
  65.                err, __LINE__, __FILE__); }
  66.  
  67. //------------------------------------------------------------------------
  68. //                             Notification posting
  69. // The set of functions below let a (backgound) application to post 
  70. // synchronous or asynchronous notification messages to the user.
  71. // Synchronous posting means that function does not return until the
  72. // notification message is displayed and the user dismisses it.
  73. // In asynchronous mode, the posting function returns as soon as the
  74. // message is queued into the notification queue (but not yet displayed!).
  75. // 
  76.  
  77. void notify_and_wait(const char * messg,...);
  78. void notify(const char * messg,...);
  79.  
  80. //------------------------------------------------------------------------
  81. //                            Sound playing on errors
  82.  
  83. void set_error_sound(Str255 sound_name);
  84.  
  85. //------------------------------------------------------------------------
  86. //                            Macintosh System Utilities
  87.  
  88. void Initialize_MAC(void);
  89. void sleep(const int nticks);            // Generous suspension for a specified no. of ticks
  90.  
  91.                                         // Launch an application and have it handle the
  92.                                         // specified file, as if the file were
  93.                                         // "double-clicked"
  94. void open_selection(const char * full_path_name);
  95.  
  96.  
  97. #endif
  98.